package com.koron.css2.clientCenter.impl;

import com.koron.common.bean.query.BaseQueryBean;
import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.UserBean;
import com.koron.css2.clientCenter.bean.UserDetailInfoBean;
import com.koron.css2.clientCenter.mapper.UserInfoMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户信息模糊查询
 * @author bin
 *
 */
public class UserInfoFuzzyQuery implements ServerInterface{

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			@SuppressWarnings("rawtypes")
			MessageBean<List> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", List.class);
			BaseQueryBean query = JsonUtils.objectToPojo(req.getData(), BaseQueryBean.class);
			UserInfoMapper mapper = factory.getMapper(UserInfoMapper.class);
			List<UserBean> users = mapper.fuzzyQueryUserInfo(query.getFuzzyQuery(), UserBean.USER);
			List<UserDetailInfoBean> userDetails = new ArrayList<UserDetailInfoBean>();
			UserInfoQuery u = new UserInfoQuery();
			for(UserBean user : users) {
				UserDetailInfoBean userDetail = u.getUserDetailInfoByUser(factory, user,userInfo);
				userDetails.add(userDetail);
			}
			info.setData(userDetails);
			return info;
		} catch (Exception e) {
			logger.error("用户信息列表查询失败", e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败", null);
		}
	}

}
